/**
 *
 */
package com.angel.data.generator.checkers.impl;

import com.angel.data.generator.checkers.DataGeneratorChecker;
import com.angel.data.generator.exceptions.DataGeneratorException;
import com.angel.data.generator.interfaces.DataGenerator;
import com.angel.data.generator.repository.DataGeneratorRepository;

/**
 * @author William
 *
 */
public class DependsDataGeneratorDependenceNotAddedChecker implements DataGeneratorChecker{


	public void checkDataGenerator(DataGenerator dataGenerator, DataGenerator[] dependencies) throws DataGeneratorException {
		//TODO Verify singleton instance.
		DataGenerator[] dataGeneratorDependencies = DataGeneratorRepository.getInstance().getDependenciesFor(dataGenerator.getClass());
		if(dataGeneratorDependencies != null && dataGeneratorDependencies.length > 0 && dependencies != null && dependencies.length > 0){
			for(DataGenerator dataGeneratorDependency: dataGeneratorDependencies){
				int dependenceCount = dataGeneratorDependencies.length;
				for(DataGenerator dependency: dependencies){
					if(dataGeneratorDependency.getClass().equals(dependency.getClass())){
						dependenceCount--;
					}
				}
				if( dependenceCount > 0){
					throw new DataGeneratorException("Some dependencies for data generator class [" + dataGenerator.getClass() + "] was not found. It found only [" + dependenceCount + "] dependences.");
				}
			}
		}
	}


}
